package canglang.monitor.cases.service.impl;

import canglang.monitor.cases.dao.CaseFourDAO;
import canglang.monitor.cases.model.CaseFourModel;
import canglang.monitor.cases.model.CaseLightModel;
import canglang.monitor.cases.service.CaseFourMgr;
import canglang.monitor.cases.service.CaseLightMgr;
import canglang.monitor.cases.to.SearchFourTO;
import canglang.monitor.core.base.pagination.PaginatedListHelper;
import canglang.monitor.core.base.util.DateUtil;

import java.util.List;
import java.util.Date;

public class CaseFourMgrImpl implements CaseFourMgr {

    private CaseFourDAO caseFourDAO;

    private CaseLightMgr caseLightMgr;

    public void setCaseLightMgr(CaseLightMgr caseLightMgr) {
        this.caseLightMgr = caseLightMgr;
    }

    public void setCaseFourDAO(CaseFourDAO caseFourDAO) {
        this.caseFourDAO = caseFourDAO;
    }

    public CaseFourModel addCaseFour(CaseFourModel caseFourModel) {
        int id = caseFourDAO.addCaseFour(caseFourModel);
        CaseLightModel caseLightModel = new CaseLightModel();
        caseLightModel.setCaseType("04");
        caseLightModel.setCaseId(id);
        caseLightModel.setDeptId(caseFourModel.getDeptId());
        caseLightModel.setPplInd("N");
        caseLightModel.setProcInd("N");        
        caseLightModel.setLightInd("N");
        Date date = DateUtil.getDate();
        caseLightModel.setCreateId(caseFourModel.getCreateId());
        caseLightModel.setUpdateId(caseFourModel.getCreateId());
        caseLightModel.setCreateDt(date);
        caseLightModel.setUpdateDt(date);
        caseLightMgr.addCaseLight(caseLightModel);
        return caseFourDAO.getCaseFour(id);
    }

    public CaseFourModel getCaseFour(int caseFourId) {
        return caseFourDAO.getCaseFour(caseFourId);
    }

    public CaseFourModel saveCaseFour(CaseFourModel caseFourModel) {
        caseFourDAO.saveCaseFour(caseFourModel);
        caseLightMgr.updateLightDept("04",caseFourModel.getCaseFourId(),caseFourModel.getDeptId());
        return caseFourDAO.getCaseFour(caseFourModel.getCaseFourId());
    }

    public void deleteCaseFour(int caseFourId) {
        caseLightMgr.deleteUnuseLight("04",caseFourId);
        caseFourDAO.deleteCaseFour(caseFourId);
    }

    public PaginatedListHelper search(PaginatedListHelper helper, SearchFourTO searchTO) {
        int count = caseFourDAO.searchCount(searchTO);
        helper.setFullListSize(count);
        List list = caseFourDAO.searchList(helper, searchTO);
        helper.setList(list);
        return helper;
    }

    public List getCaseFourList(SearchFourTO searchTO) {
        return caseFourDAO.getCaseFourList(searchTO);
    }
}
